package com.neusoft.controller;

import com.neusoft.entity.BanJi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("banji/consumer")
public class BanjiComsumerController {

    @Autowired
    private RestTemplate restTemplate; //提供一些便利的方法直接访问http请求

    private String url_prefix = "http://provider-banji";

    @RequestMapping("insert")
    public ResponseEntity<Boolean> insert(BanJi bean) {
        String uri = url_prefix + "/banji/insert";//"http://localhost:8001/banji/insert";
        return restTemplate.postForEntity(uri, bean, Boolean.class);
    }

    @RequestMapping("queryAll")
    public Object queryAll() {
        String uri = url_prefix + "/banji/queryAll";//"http://localhost:8001/banji/queryAll";
        return restTemplate.getForObject(uri, List.class);
    }

    @RequestMapping("queryById/{id}")
    public Object queryById(@PathVariable Integer id) {
        String uri = url_prefix + "/banji/queryById/"+ id;//"http://localhost:8001/banji/queryAll";
        return restTemplate.getForObject(uri, BanJi.class);
    }
}
